package tij4.concurrent.exercise.ex15;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Ex15 {
    Object object1 = new Object();
    Object object2 = new Object();
    Object object3 = new Object();

    public void fun1() {
        synchronized (object1) {
//            synchronized (this) {
            while (true) {
                System.out.println("fun1()");
            }
        }
    }

    public void fun2() {
        synchronized (object2) {
//            synchronized (this) {
            while (true) {
                System.out.println("fun2()");
            }
        }
    }

    public void fun3() {
        synchronized (object3) {
//            synchronized (this) {
            while (true) {
                System.out.println("fun3()");
            }
        }
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        Ex15 ex15 = new Ex15();
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                ex15.fun1();
            }
        });
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                ex15.fun2();
            }
        });
        ex15.fun3();

    }
}
